<div id="subMenu">
	<ul>
		<li<?php echo  ($actualController == 'pages' && ($actualAction == 'index' || $actualAction == 'display')) ? ' class="active"' : ''?>><?php
			echo $this->Html->link('HOMEPAGE', array('controller' => 'pages'));
			?>
		</li>
		<?php if ($menuItems): ?>
			<?php foreach ($menuItems as $key => $controller): ?>
				<?php if (isset($controller['title'])): ?>
					<li<?php if (isset($controller['active']) && $controller['active'] === TRUE): ?> class="active"<?php endif; ?>>
					<?php echo $this->Html->link($controller['title'], array('controller' => $key, 'action' => $controller['actions'][0]['action']));
					if (isset($controller['active']) && $controller['active'] === TRUE && $controller['actions']) {
						$secondLevel = $controller['actions'];
					} ?>
					</li>
				<?php endif; ?>
			<?php endforeach; ?>
		<?php endif; ?>
	</ul>
</div>
<div class="clear"></div>
<?php if (isset($secondLevel)): ?>
	<div class="listing"> 
		<div id="button_links">
			<?php foreach($secondLevel as $actionKey => $action): ?>
				<?php if (is_string($actionKey) && $actionKey == 'next_level'): ?>
					<?php
						$class = '';
						if (isset($action['active']) && $action['active'] === TRUE) {
							$thirdLevel = $action;
							$class = 'active';
						}
					?>
					<?php echo $this->Html->link($action['controller']['title'], array('controller' => $action['actions'][0]['controller'], 'action' => $action['actions'][0]['action']), array('class' => $class)); ?>
				<?php else:?>
					<?php 
					$class = '';
					if (isset($action['active']) && $action['active'] === TRUE) {
						$class = 'active';
					} ?>
					<?php echo $this->Html->link($action['action_title'], array('controller' => $action['controller'], 'action' => $action['action']), array('class' => $class)); ?>
				<?php endif; ?>
			<?php endforeach; ?>
			<?php if (isset($thirdLevel)): ?>
			<div class="clear"></div>
				<?php foreach ($thirdLevel['actions'] as $nextLevelAction): ?>
				<?php
					$class = '';
					if (isset($nextLevelAction['active']) && $nextLevelAction['active'] === TRUE) {
						$class = 'active';
					}
				?>
				<?php echo $this->Html->link($nextLevelAction['action_title'], array('controller' => $nextLevelAction['controller'], 'action' => $nextLevelAction['action']), array('class' => $class)); ?>
				<?php endforeach; ?>
			<?php endif; ?>
		</div>
	</div>
<?php endif; ?>